package com.example.clxy.controller;

import com.example.clxy.entity.Course;
import com.example.clxy.interceptor.AppToken;
import com.example.clxy.result.PageResult;
import com.example.clxy.result.WebRestResult;
import com.example.clxy.result.business.CourseOneResult;
import com.example.clxy.result.business.PageResult.CoursePageResult;
import com.example.clxy.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author liuhaoqi
 * @Date 2020/8/8 10:10
 * @Version 1.0
 */
@RestController
@RequestMapping("CourseController")
@AppToken
public class CourseController {

    @Autowired
    CourseService courseService;

    /**
     * 新增理论课程
     * @param course
     * @return
     */
    @CrossOrigin
    @PostMapping("addCourse")
    public WebRestResult addCourse(@RequestBody Course course) {
        WebRestResult result = courseService.addCourse(course);
        return result;
    }

    /**
     * 更新理论课程
     * @param course
     * @return
     */
    @CrossOrigin
    @PostMapping("updateCourse")
    public WebRestResult updateCourse(@RequestBody Course course) {
        WebRestResult result = courseService.updateCourse(course);
        return result;
    }

    /**
     * 删除理论课程
     * @param courseid
     * @return
     */
    @CrossOrigin
    @PostMapping("deleteCourse")
    public WebRestResult deleteCourse(String courseid) {
        WebRestResult result = courseService.deleteCourse(courseid);
        return result;
    }

    /**
     * 获取理论课程列表
     * @param page
     * @param pagesize
     * @param coursename
     * @param coursecode
     * @param coursetype
     * @param coursesemester
     * @return
     */
    @CrossOrigin
    @GetMapping("getCourseList")
    public PageResult<CoursePageResult> getCourseList(int page, int pagesize, String coursename, String coursecode,
                                                      String coursetype, String coursesemester) {
        PageResult<CoursePageResult> result = courseService.getCourseList(page, pagesize, coursename, coursecode, coursetype, coursesemester);
        return result;
    }

    /**
     * 根据理论课程id查询理论课程
     * @param courseid
     * @return
     */
    @CrossOrigin
    @GetMapping("getCourseById")
    public CourseOneResult getCourseById(String courseid) {
        CourseOneResult result =courseService.getCourseById(courseid);
        return result;
    }
}
